<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>人员列表</title>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    {CSS href="__ADDONSTATIC__css/font.css" /}
    {CSS href="__ADDONSTATIC__css/xadmin.css" /}
    {js href='__ADDONSTATIC__js/jquery-3.2.1.min.js' /}

    {js href='__ADDONSTATIC__js/xadmin.js' /}
    {js href='__ADDONSTATIC__js/util.js' /}
    {js href='__ADDONSTATIC__lib/layui/layui.js' /}
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body" id="page">
    <div class="layui-row">
        <form id="sear" name="sear" class="layui-form layui-col-md12 x-so" action="{:addonUrl('Project/pagepush')}?page={$page}">
            <input type="text" name="name" placeholder="请输入项目名" autocomplete="off" value="{$name}"
                   class="layui-input">
            <input type="text" name="position" placeholder="请输入坐落位置" autocomplete="off" value="{$position}"
                   class="layui-input">
            <div class="layui-input-inline">
                <select id="type" name="type">
                    <option value="" selected>项目种类</option>
                    {volist name="typeList" id="types"}
                    {if condition="$type == $types.id"}
                    <option value="{$types.id}" selected>{$types.name}({$types.parent})</option>
                    {else/}
                    <option value="{$types.id}">{$types.name}({$types.parent})</option>
                    {/if}
                    {/volist}
                </select>
            </div>
            <div class="layui-input-inline">
                <select id="evaStatus" name="evaStatus">
                    <option value="">评价状态</option>
                    <option value="1" {if condition="$evaStatus == '1'"} selected {/if}>已评价</option>
                    <option value="0" {if condition="$evaStatus == '0'"} selected {/if}>未评价</option>
                </select>
            </div>
            <button type="submit" lay-filter="search" lay-submit="" class="layui-btn"><i class="layui-icon">&#xe615;</i>
            </button>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
               href="javascript:location.replace(location.href.slice(0,location.href.indexOf('mid')+5));" title="刷新">
                <i class="layui-icon" style="line-height:30px">ဂ</i></a>
        </form>
    </div>
    <xblock>
        <button class="layui-btn" onclick="pushEvaluates()">批量推送</button>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <!--选择-->
                <input id="allChoose" type="checkbox" class="layui-form-checkbox" lay-skin="primary" lay-filter="allChoose" title='全选'>
            </th>
            <th>序号</th>
            <th>项目编码</th>
            <th>项目名称</th>
            <th>项目种类</th>
            <th>项目阶段</th>
            <th>项目状态</th>
            <th>本周推送状态</th>
            <th>截止时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name='list' id='l'}
        <tr>
            <td><input class="layui-form-checkbox" type="checkbox" value="{$l.id}" name="pushCheck" lay-skin="primary"></td>
            <td>{$i+($page-1)*10}</td>
            <td>{$l.id}</td>
            <td title="{$l.name}" onclick="x_admin_show('项目信息','{:addonUrl('Project/projectInfo')}?projectId={$l.id}')">
                <!--<a title="评价详情" target="_blank" href="{:addonUrl('Project/projectInfo')}?projectId={$l.id}">-->
                {$l.name|subtext=20}
                <!--</a>-->
            </td>
            <td>{$l.type | getProjectTypeName}</td>
            <td class="td-stage">{$l.stage|getPStageAttr}</td>
            <td class="td-status">{$l.status|getPStatusAttr}</td>
            <th>{$l.isPush|getPIsPushAttr}</th>
            <td>{$l.end_time|stamp2date}</td>
            <td class="td-manage">
                <button class="layui-btn" onclick="push({$l.id})">推送</button>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <!--分页页面-->
    <?php echo $list->render() ?>
</div>

<script>

    /**
     * 全选,不全选
     *
     */
    $("#allChoose").click(function(){
        var isChecked = $("#allChoose").prop('checked');
        if (isChecked){
            //全选
            $("input[name='pushCheck']").prop("checked",true);
        }else{
            //不全选
            $("input[name='pushCheck']").prop("checked",false);
        }
    });

    /**
     * 批量推送评价
     */
    function pushEvaluates(){
        var data ={};
        data.ids=[];
        $("input[name='pushCheck']:checked").each(function(){
            var id = $(this).val();
            data.ids.push(id);
        });
        pushAjax(data);
        console.log(data.ids);
    }

    /**
     * 推送单个评价
     */
    function push(id){
        var data ={};
        data.ids=[];
        data.ids.push(id);
        pushAjax(data);
    }
    /**
     * 推送消息ajax
     * @param data
     */
    function pushAjax(data) {
         var that = data;
        layer.confirm('确定推送么？', function(index1){
          //do something
          ajaxUrl("{:addonUrl('Project/pushEvaluates')}",that,function (res) {
                      console.log(res);
                      if (res.code == 1) {
                          layer.alert('推送成功!',{},function(index){
                              layer.close(index);
                              $("form[name='sear']").submit();
                          });
                      }else{
                          layer.alert(res.message);
                      }
                  })
          layer.close(index1);
        });
    }

    /**
     * 保留接口
     * 判断本年本周是否推送过评价信息
     */
    function ispushed(data){

    }
</script>
</body>

</html>